<template>
  <t-tabs v-model:value="clueDetails.selectedTab" :list="list" />
</template>

<script setup lang="ts">
import { MessagePlugin } from 'tdesign-vue-next';
import { computed, inject, Ref, watch } from 'vue';

import { useDictionaryStore } from '@/store';

// 字典仓库
const dictionaryStore = useDictionaryStore();
// 订单详情
const clueDetails = inject<Ref<Record<string, any>>>('clueDetails');
// 列表
const list = computed(() => {
  const result = [{ label: '跟进记录', value: '跟进记录' }];
  return result;
});
// 设置选中的标签
watch(
  list,
  () => {
    let selectedTab = list.value[0]?.value;
    const { operateType, approveType } = clueDetails.value;
    console.log(operateType,'operateType');
    console.log(approveType,'approveType');
    
    if (operateType) {
      let operateTypeConfig = { tab: '' };
      try {
        const operateTypeDictionary: Record<string, any> =
          dictionaryStore.get('decoration_order_operate_type').find((item) => item.value === operateType) || {};
        operateTypeConfig = JSON.parse(operateTypeDictionary.remark);
        if (operateTypeConfig.tab) selectedTab = operateTypeConfig.tab;
      } catch {
        MessagePlugin.warning('解析操作配置失败，请联系管理员。');
      }
    } else if (approveType) {
      let approveTypeConfig = { tab: '' };
      try {
        const approveTypeDictionary: Record<string, any> =
          dictionaryStore.get('order_approval_type').find((item) => item.value === approveType) || {};
        approveTypeConfig = JSON.parse(approveTypeDictionary.remark);
        console.log(approveTypeDictionary,'approveTypeDictionary');
        console.log(approveTypeConfig,'approveTypeConfig');
        
        if (approveTypeConfig.tab) selectedTab = approveTypeConfig.tab;
      } catch {
        MessagePlugin.warning('解析审批配置失败，请联系管理员。');
      }
    }
    clueDetails.value.selectedTab = selectedTab;
  },
  { immediate: true },
);
</script>
